﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using SVC.client;
namespace UI.Forms
{
    public partial class goodsclass_U : DevExpress.XtraEditors.XtraForm
    {
        public delegate void DoAction();//如果有参数的话，定义参数 

        public DoAction FatherRefresh;
        private GoodsClass gc=null;
        public goodsclass_U(GoodsClass _gc)
        {
            InitializeComponent();
            gc = _gc;

        }

        private void btn_new_Click(object sender, EventArgs e)
        {

        }

        private void bindTreelist()
        {
            treeList1.DataSource = my.bw.GoodsClass_Get("ClassID", my.ACID);
            treeList1.ExpandAll();
        }

        private void goodsclass_N_Load(object sender, EventArgs e)
        {
            bindTreelist();
            textEdit1.Text = gc.ClassName;
            textEdit2.Text = gc.ClassID;
            if (!string.IsNullOrWhiteSpace(gc.ParentID))
            {
                GoodsClass pgc=my.bw.GoodsClassByClassID_Get(gc.ParentID,my.ACID);
                popupContainerEdit1.EditValue = string.Format("{0},{1}",pgc.ClassID,pgc.ClassName);
            }
            treeList1.EditingValue = gc.ParentID;
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            GoodsClass PGC = treeList1.GetDataRecordByNode(treeList1.FocusedNode) as GoodsClass;
            popupContainerEdit1.EditValue = string.Format("{0},{1}", PGC.ClassID, PGC.ClassName);
            popupContainerEdit1.ClosePopup();
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            popupContainerEdit1.Text = "";
            popupContainerEdit1.ClosePopup();
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (!dxValidationProvider1.Validate()) return;

            gc.ClassName = textEdit1.Text.Trim();
            if (!string.IsNullOrWhiteSpace(popupContainerEdit1.Text))
            {
                gc.ParentID = popupContainerEdit1.Text.Split(',')[0];
            }
            string result = my.bw.GoodsClass_Update(gc, my.ACID);
            if (string.IsNullOrWhiteSpace(result))
            {
                FatherRefresh();
                this.Close();
            }
            else
            {
                Comm.ShowErorr(result);
            }
        }

    }
}